//
//  TestViewController.m
//  TimerTest
//
//  Created by wangrui on 13-8-13.
//  Copyright (c) 2013年 PPS. All rights reserved.
//

#import "TestViewController.h"

static int ObjectCount = 0;

@implementation TestViewController

- (void)viewDidLoad{
    [super viewDidLoad];

    UIButton *bt = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    bt.frame = CGRectMake(0, 0, 50, 20);
    bt.center = self.view.center;
    [bt addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:bt];
    
    
    ObjectIndex = ++ ObjectCount;
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeEvent:) userInfo:nil repeats:YES];
}

- (void)back:(id)sender{
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}

- (void)timeEvent:(id)sender{
    NSLog(@"instance %d : timer invoke",ObjectIndex);
    static int count = 0;
    count ++;
    if (count>5) {
        count = 0;
        [self validateTimer];
    }
}

- (void)validateTimer{
    [timer invalidate];
}


- (void)dealloc{
    NSLog(@"instance %d : dealloc",ObjectIndex);
    [super dealloc];
}



@end
